package com.gilgamesh.mall.product.service.impl;

import com.gilgamesh.mall.product.dao.OutofstockDao;
import com.gilgamesh.mall.product.service.OutofstockService;
import com.gilgamesh.mall.sdk.bean.product.OutofstockEntity;
import com.gilgamesh.mall.sdk.dto.ResponseDTO;
import com.gilgamesh.mall.sdk.dto.product.OutofstockDTO;
import com.gilgamesh.mall.sdk.util.BeanUtil;
import com.gilgamesh.mall.sdk.util.CollectionUtil;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by Peiyao.Wang on 2021/1/13
 *
 * @author Peiyao.Wang
 * @date 2021/1/13
 */
@Service
@Slf4j
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class OutofstockServiceImpl implements OutofstockService {

    final OutofstockDao outofstockDao;

    @Override
    public ResponseDTO<OutofstockDTO> getOutofstockById(Long id) {

            ResponseDTO<OutofstockDTO> responseDTO = new ResponseDTO<>();
            OutofstockDTO outofstockDTO = outofstockDao.getOutofstockById(id);
            responseDTO.setData(outofstockDTO);
            if(BeanUtil.isLogicalNull(responseDTO)){
                responseDTO.setCode("0");
                responseDTO.setMessage("success");
                responseDTO.setSuccess(Boolean.TRUE);
            }
            return responseDTO;
    }

    @Override
    public ResponseDTO<List<OutofstockDTO>> listOutofstockDTOl(OutofstockEntity outofstockEntity) {
        if (log.isDebugEnabled()) {
            log.debug("outofstockEntity is,{}", outofstockEntity);
        }
        ResponseDTO<List<OutofstockDTO>> responseDTO = new ResponseDTO<>();
        responseDTO.setData(outofstockDao.listOutofstocks(outofstockEntity));
        if (CollectionUtil.isNotEmpty(responseDTO.getData())) {
            responseDTO.setCode("0");
            responseDTO.setMessage("success");
            responseDTO.setSuccess(Boolean.TRUE);
        }
        return responseDTO;
    }
}
